package com.example.service;

import com.example.entity.Post;
import com.example.entity.Task;
import com.example.mapper.PostMapper;
import com.example.mapper.TaskMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
帖子业务处理
 */
@Service
public class TaskService {

    @Resource
    private TaskMapper taskMapper;

    public void add(Task task) {
        taskMapper.insert(task);
    }

    public void deleteById(Integer id) {
        taskMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(Task task) {
        taskMapper.updateById(task);
    }

    public Task selectById(Integer id) {
        return taskMapper.selectById(id);
    }

    public List<Task> selectAll(Task task) {
        return taskMapper.selectAll(task);
    }

    public PageInfo<Task> selectPage(Task task, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Task> taskList = taskMapper.selectAll(task);
        return PageInfo.of(taskList);
    }
}
